<?php

declare(strict_types=1);

namespace app\Controller\WebApi\v1;

use App\Controller\AbstractController;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Service\ConfigService\MnConfigService;
use Service\ConfigService\BankService;
use Service\MnCheckUserService\MnCheckUserService;
use Service\MnGoodsService\MnGoodsService;
use Service\UserService\MnUserService;
use Service\MnGoodsService\MnStoreGoodsService;

/**
 * 分销接口数据
 * @author Luoshumai
 * @Controller(prefix="/webapi/v1/distribution")
 */
class DistributionController extends AbstractController
{
    /**
     * Inject()
     * @var MnConfigService
     */
    protected $mnConfigService;

    /**
     * Inject()
     * @var BankService
     */
    protected $bankService;

    /**
     * Inject()
     * @var MnCheckUserService
     */
    protected $mnCheckUserService;

    /**
     * Inject()
     * @var MnGoodsService
     */
    protected $mnGoodsService;

    /**
     * Inject()
     * @var MnUserService
     */
    protected $mnUserService;

    /**
     * Inject()
     * @var MnStoreGoodsService
     */
    protected $mnStoreGoodsService;

    /**
     * 判断是否开通渠道
     * @RequestMapping(path="checkStore", methods="post")
     */
    public function checkStore(RequestInterface $request)
    {
        return $this->mnConfigService->checkStore(
            (int)$request->input('mnid'),
            (int)$request->input('mid')
        );
    }

    /**
     * 判断是否开通渠道
     * @RequestMapping(path="checkGlobalStore", methods="post")
     */
    public function checkGlobalStore(RequestInterface $request)
    {
        return $this->mnConfigService->checkGlobalStore(
            (int)$request->input('mnid'),
            (int)$request->input('cid'),
            (int)$request->input('mid')
        );
    }

    /**
     * 获取邀请开店页面富文本内容
     * @RequestMapping(path="getText", methods="post")
     */
    public function getText(RequestInterface $request)
    {
        return $this->mnConfigService->getText(
            (int)$request->input('mnid'),
            (int)$request->input('cid')
        );
    }

    /**
     * 获取开店图片
     * @RequestMapping(path="getImage", methods="post")
     */
    public function getImage(RequestInterface $request)
    {
        return $this->mnConfigService->getImage(
            (int)$request->input('mnid'),
            (int)$request->input('cid')
        );
    }

    /**
     * 开通小店
     * @RequestMapping(path="openStore", methods="post")
     */
    public function openStore(RequestInterface $request)
    {
        $params = $request->inputs([
            'mnid', 'img', 'store_name', 'cid', 'channel_id', 'link_man', 'link_mobile', 'sms_code', 'id_card', 'invite_code'
        ]);
        $params['mid'] = (int)$request->input('mid');
        $params['is_manager'] = 0;
        return $this->mnConfigService->openStore($params);
    }

    /**
     * 获取银行列表
     * @RequestMapping(path="getBankList", methods="post")
     */
    public function getBankList()
    {
        return $this->bankService->getBankList();
    }

    /**
     * 获取银行列表
     * @RequestMapping(path="applyUser", methods="post")
     */
    public function applyUser(RequestInterface $request)
    {
        return $this->mnCheckUserService->applyUser(
            (int)$request->input('mnid'),
            (string)$request->input('mobile'),
            (string)$request->input('name'),
            (int)$request->input('cid'),
            (string)$request->input('invite_code'),
            (int)$request->input('mid')
        );
    }

    /**
     * 全球仓小程序市场分类
     * @RequestMapping(path="getClass", methods="post")
     */
    public function getClass()
    {
        return $this->mnGoodsService->getClass();
    }

    /**
     * 跨境Q店商铺分类
     * @RequestMapping(path="getGlobalClass", methods="post")
     */
    public function getGlobalClass(RequestInterface $request)
    {
        return $this->mnGoodsService->getGlobalClass(
            (int)$request->input('mnid'),
            (int)$request->input('mn_sid')
        );
    }

    /**
     * 小店首页
     * @RequestMapping(path="storeIndex", methods="post")
     */
    public function storeIndex(RequestInterface $request)
    {
        return $this->mnUserService->storeIndex(
            (int)$request->input('mnid'),
            (int)$request->input('cid'),
            (int)$request->input('mn_sid'),
            (int)$request->input('mid'),
        );
    }

    /**
     * 根据终端扫码获取购物车id获取购物车商品
     * @RequestMapping(path="getCartGoodsList", methods="post")
     */
    public function getCartGoodsList(RequestInterface $request)
    {
        return $this->mnStoreGoodsService->getCartGoodsList(
            (int)$request->input('mnid'),
            (int)$request->input('mn_sid'),
            (int)$request->input('cart_id'),
            (int)$request->input('cid'),
            (int)$request->input('mid'),
        );
    }

    /**
     * 小店商品置顶取消置顶
     * @RequestMapping(path="upGoods", methods="post")
     */
    public function upGoods(RequestInterface $request)
    {
        return $this->mnStoreGoodsService->upGoods(
            (int)$request->input('mnid'),
            (int)$request->input('goods_id'),
            (int)$request->input('up'),
            (int)$request->input('cid'),
            (int)$request->input('mn_sid'),
            (int)$request->input('mid'),
        );
    }

    /**
     * 小店商品排序
     * @RequestMapping(path="sortGoods", methods="post")
     */
    public function sortGoods(RequestInterface $request)
    {
        return $this->mnStoreGoodsService->sortGoods(
            (int)$request->input('mnid'),
            (int)$request->input('goods_id'),
            (int)$request->input('type'),
            (int)$request->input('cid'),
            (int)$request->input('mn_sid'),
            (int)$request->input('mid'),
        );
    }

    /**
     * 线下门店列表
     * @RequestMapping(path="shopList", methods="post")
     */
    public function shopList(RequestInterface $request)
    {
        return $this->mnUserService->shopList(
            (int)$request->input('mnid'),
            (int)$request->input('cid'),
            (int)$request->input('mn_sid'),
            (int)$request->input('page'),
            (int)$request->input('limit'),
            (int)$request->input('mid')
        );
    }

    /**
     * 小店分类列表
     * @RequestMapping(path="classList", methods="post")
     */
    public function classList(RequestInterface $request)
    {
        return $this->mnStoreGoodsService->classList(
            (int)$request->input('mnid'),
            (int)$request->input('cid'),
            (int)$request->input('mn_sid'),
            (int)$request->input('page'),
            (int)$request->input('limit'),
            (int)$request->input('mid')
        );
    }

    /**
     * 申请小店资料变更
     * @RequestMapping(path="applyCheck", methods="post")
     */
    public function applyCheck(RequestInterface $request)
    {
        return $this->mnUserService->applyCheck(
            (int)$request->input('mnid'),
            (string)$request->input('store_name'),
            (string)$request->input('img'),
            (int)$request->input('cid'),
            (int)$request->input('mn_sid'),
            (int)$request->input('mid')
        );
    }

    /**
     * 小店资料
     * @RequestMapping(path="storeInfo", methods="post")
     */
    public function storeInfo(RequestInterface $request)
    {
        return $this->mnUserService->getInfo(
            (int)$request->input('mnid'),
            (int)$request->input('mn_sid'),
            (int)$request->input('cid'),
            (int)$request->input('mid')
        );
    }

    /**
     * 小店广告模板列表
     * @RequestMapping(path="storeTemp", methods="post")
     */
    public function storeTemp(RequestInterface $request)
    {
        return $this->mnUserService->storeTemp(
            (int)$request->input('mnid'),
            (int)$request->input('cid'),
            (int)$request->input('mn_sid'),
            (int)$request->input('mid')
        );
    }

    /**
     * 店铺设置装修模板
     * @RequestMapping(path="setTemplate", methods="post")
     */
    public function setTemplate(RequestInterface $request)
    {
        return $this->mnUserService->setStoreTemp(
            (int)$request->input('mnid'),
            (int)$request->input('temp_id'),
            (int)$request->input('cid'),
            (int)$request->input('mn_sid'),
            (int)$request->input('mid')
        );
    }

    /**
     * 获取搜索建议接口
     * @RequestMapping(path="getRelativeWord", methods="post")
     */
    public function getRelativeWord(RequestInterface $request,StoreCommodityIndex $storeCommodity)
    {
        $mn_sid     = (int)$request->input('mn_sid');
        $keyword    = $request->input('keyword');
        $type       = $request->input('type');
        return $this->StoreCommodityIndex->searchSuggest($mn_sid,$keyword);
    }
}
